package com.office.supplies.controller;

import com.office.supplies.pojo.Result;
import com.office.supplies.pojo.vo.CountVO;
import com.office.supplies.pojo.vo.SaleStatisticsVO;
import com.office.supplies.pojo.vo.SalesProportionOfGoodsVO;
import com.office.supplies.pojo.vo.TurnoverVO;
import com.office.supplies.service.StatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

/**
 * @Author admin
 * @Description TODO
 * @Date 2023/12/13/9:56
 */
@RestController
@Slf4j
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;


    /**
     * 营业额统计
     *
     * @param begin Date
     * @param end   Date
     * @return Result<TurnoverVO>
     */
    @GetMapping("/getTurnoverStatistics")
    public Result<TurnoverVO> getTurnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        log.info("营业统计:{},{}", begin, end);
        return Result.success(statisticsService.getTurnoverStatistics(begin, end));
    }

    @GetMapping("/getSaleStatistics")
    public Result<SaleStatisticsVO> getSaleStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        log.info("出库统计:{},{}", begin, end);
        return Result.success(statisticsService.getSaleStatistics(begin, end));
    }

    /**
     * 总体销售占比
     *
     * @return Result<SalesProportionOfGoodsVO>
     */
    @GetMapping("/salesProportionOfGoods")
    public Result<List<SalesProportionOfGoodsVO>> salesProportionOfGoods() {
        log.info("总体销售占比... ...");
        return Result.success(statisticsService.getSalesProportionOfGoods());
    }

    /**
     * 获取库存数，销售订单数，采购订单数
     *
     * @return Result<CountVO>
     */
    @GetMapping("/getAllCount")
    public Result<CountVO> getAllCount() {
        log.info("获取库存数，销售订单数，采购订单数");
        return Result.success(statisticsService.getAllCount());
    }

}
